package com.jt.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ItemController {

    //启动时是否校验有服务提供者
    @Reference(check = false)
    private DubboItemService itemService;


    /**
     * 根据商品ID查询商品信息
     * 1.URL地址:http://www.jt.com/items/562379.html
     * 2.参数: 562379 restFul风格
     * 3.返回值:String
     * */

    @RequestMapping("/items/{itemId}")
    public String  findItemById(@PathVariable Long itemId, Model model){
        //1.获取商品相关信息
        Item item = itemService.findItemById(itemId);
        ItemDesc itemDesc = itemService.finItrmDescById(itemId);

        //2.如何将数据传递到页面中?
        model.addAttribute("item",item);
        model.addAttribute("itemDesc",itemDesc);

        //跳转到商品展现页面
        return "item";
    }

}
